// pages/hall/order/order.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    itemList: [
      // {id:1},
      // {id:1},
      // {id:1},
      // {id:2}
    ],
    noMore: 0,
    page: 1,
  },
  cuts(){
    wx.reLaunch({
      url: '/pages/hall/index',
    })
  },
  detail(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: './detail?id='+id
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getList();
  },
  getList() {
    let page = this.data.page
    let itemList = this.data.itemList
    app.util.request({
      url: '/tasks/mytasks',
      data: {
        page: page
      }
    }).then((res) => {
      if (res.data.list.length > 0) {
        this.setData({
          itemList: itemList.concat(res.data.list),
          noMore: 0,
          page: page + 1
        });
      } else {
        this.setData({
          noMore: 1
        });
      }
    });
  },
  refreshList: function () {
    this.setData({
      page: 1,
      itemList: []
    });
    this.getList();
  },
  onPullDownRefresh() {
    this.refreshList();
    setTimeout(() => {
      wx.hideNavigationBarLoading(); //完成停止加载
      wx.stopPullDownRefresh(); //停止下拉刷新
    }, 500);
  },
  onReachBottom() {
    this.getList();
  }
})